package cheme.Application.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;

import cheme.Application.ChemeApplicationConstants;
import cheme.Application.ProjectSpaceModel.ChemeProjectModel;
import cheme.ProcessEditor.ChemeFileInput;
import cheme.ProcessEditor.ProcessEditor;

public class NewFileAction extends Action implements ActionFactory.IWorkbenchAction
{
	/**
     * The workbench window this action is registered with.
     */
    private IWorkbenchWindow workbenchWindow;
    
    public NewFileAction(IWorkbenchWindow window)
    {
        //super(WorkbenchMessages.SaveAction_text, window); 
    	
    	super("");
        
    	if (window == null)
        {
            throw new IllegalArgumentException();
        }
    	
        workbenchWindow = window;
        
        setText(ChemeApplicationConstants.NEW_FILE_ACTION_TEXT);
        setToolTipText(ChemeApplicationConstants.NEW_FILE_ACTION_TOOLTIP);
        setId("new"); //$NON-NLS-1$
        
//        window.getWorkbench().getHelpSystem().setHelp(this, IWorkbenchHelpContextIds.SAVE_ACTION);
        
        setImageDescriptor(ChemeApplicationConstants.DESC_NEW);
        setDisabledImageDescriptor(ChemeApplicationConstants.DESC_NEW);
        
        setActionDefinitionId("org.eclipse.ui.file.save"); //$NON-NLS-1$
    }
    
    IWorkbenchWindow getWorkbenchWindow()
    {
    	return workbenchWindow;
    }
    
	@Override
	public void run()
	{
		ChemeFileInput input = ChemeProjectModel.getInstance().getNewFile();
		
		try
		{
			getWorkbenchWindow().getActivePage().openEditor(input, ProcessEditor.ID);
		}
		catch(Exception e)
		{
			MessageDialog.openInformation(null, getClass().getName(), e.getMessage());
			e.printStackTrace();
		}
	}

	public void dispose()
	{
	}
}